$(function(){
	
	// 项目区域数据请求
	$.ajax({
		type: "GET",
        url: "http://101.201.113.151:9230/volunteerProject/getListofArea",
        dataType: "json",
        success: function(data){
			$.each(data,function(index,item){
				$('.content').append('<span id="'+item.id+'">'+item.areaName+'</span>')
			})
			
			
		}
 
	})
	
	// 点击搜索传参  查询数据
	$('.searchbtn').click(function(){
		$.ajax({
			type: "GET",
			url: "http://101.201.113.151:9230/volunteerProject/getVolunteerProject",
			data:{
				projectId:$('.projectId').val(),
				projectTitle:$('.projectTitle').val(),
				startDate:$('.startDate').val(),
				endDate:$('.endDate').val()
				
			},
			dataType: "json",
			success: function(data){
				
				
				
			}
		})
	})
	
	$(function () {
	  var $oResultBox = $('#resultBox');
	//var books = data.books;
	
	  $.ajax({
	  	type:"get",
	  	url:"http://101.201.113.151:9230/volunteerProject/getVolunteerProject",
	  	async:true,
	  	dataType:"json",
	  	success:function(data){
	  		var books = data.result;
				
	  		console.log(books)
				
	  		  $('#paging').paging({
						    nowPage: 1,
						    allPages: Math.ceil(data.total / 8),
						    displayPage: 6,
						    callBack: function (now) {
						      var currentPages = now * 8 < books.length ? 8 : books.length - (now - 1) * 8;
						
						      // $oResultBox.html('');
						
						      for (var i = 0; i < currentPages; i++) {
						        var num = (now - 1) * 8 + i;
										
										// 图片地址
						        var showimg = 'http://101.201.113.151:9000'+books[num].showImage.split('ROOT')[1] ;
										
										var station = books[num].stations;
										var stations = '',projectId = '',stationId = '';
										
										$.each(station,function(index,item){
											 stations += item.stationName+'|';
											 projectId = item.projectId;
											 stationId += item.id+',';
											 
										})
										stations = stations.substring(0,stations.length-1)
										/* projectId = projectId.substring(0,projectId.length-1)
										stationId = stationId.substring(0,stationId.length-1)
										console.log(projectId) */
										
										//动态获取状态 设置不同颜色；state为待启动，state in为招募中 state in2为进行中 state out为已结束 
										var statuecolor = ''
										var StatueName = books[num].projectStatueName;
										if(StatueName == "待启动"){
											  statuecolor += '<div class="state right">'+StatueName+'</div>'
										}else if(StatueName == "招募中"){
											  statuecolor += '<div class="state in right">'+StatueName+'</div>'
										}else if(StatueName == "进行中"){
											  statuecolor += '<div class="state in2  right">'+StatueName+'</div>'
										}else if(StatueName == "已结束"){
											  statuecolor += '<div class="state out right">'+StatueName+'</div>'
										}
										
						        var _html = '<div class="box">'+
																'<div class="p_img">'+
																    '<input type="hidden" value="'+books[num].id+'" class="userId">'+
																    '<input type="hidden" value="'+projectId+'" class="projectId">'+
																    '<input type="hidden" value="'+stationId+'" class="stationId">'+
																    '<img src="'+showimg+'" class="img">'+
																'</div>'+
																'<div class="p_title">'+books[num].title+'</div>'+
																'<div class="num">岗位：<span>'+stations+'</span></div>'+
																'<div class="clearfix">'+
																     '<div class="num left">人数：<span>'+books[num].plansignNum+'人</span></div>'+statuecolor+'</div>'+
																
																'<div class="showbox">'+
																	'<div class="num1">'+
																		'<div>报名人数</div>'+
																		'<div>'+books[num].signNum+'</div>'+
																	'</div>'+
																	'<div class="num1">'+
																		'<div>离招募结束</div>'+
																		'<div>3天</div>'+
																	'</div>'+
																'</div>'+
															'</div>';
						        $oResultBox.append(_html);
						      }
						    },
								
								
						  });
	 
		      //点击图片区域进行 报名提交
	         $('.p_img').on('click',function(){
						 var userId = $('.userId').val();
						 var projectId = $(this).children('.projectId').val();
					
						 
						 window.location.href = "details_project.html?id="+projectId
	
	         })
	          
	  
	  	},
			
			
			
		
	  });
	
	});
	
})